package com.tzy.user.controller;
import com.tzy.common.entity.User;
import com.tzy.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * 控制器
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PutMapping("/add")
    public int saveUser(@RequestBody User user){
        return userService.insert(user);
    }

    //通过 @PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariable(“xxx“)
    @GetMapping("/info/{id}")
    public User getUserInfoById(@PathVariable int id){
        User user = userService.getById(id);
        return user;
    }
}
